package gtgold;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
 * Game Map
 * 
 * @author JoeOh, J O
 */
public class GameMap extends JDialog
{
	private static final long serialVersionUID = 1L;
	private GameManager manager;
	private int hozLoc, vertLoc;


	/**
	 * Create a new Map JDialog
	 * 
	 * @param manager
	 *            parent GameManager to retrieve game data
	 */
	public GameMap(final GameManager manager)
	{
		super(OregonTrail.frame, "Map", true);
		this.manager = manager;
		setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		setResizable(false);
		setPreferredSize(OregonTrail.VGA);

		hozLoc = 566;
		vertLoc = 258;

		// pixel coordinates for drawing wagon
		if (gameData().destination.name.equals("Kansas River") && gameData().distanceLeft <= 0)
		{
			hozLoc = 532;
			vertLoc = 261;
		} else if (gameData().destination.name.equals("Big Blue River") && gameData().distanceLeft > 0)
		{
			hozLoc = 532;
			vertLoc = 261;
		} else if (gameData().destination.name.equals("Big Blue River") && gameData().distanceLeft <= 0)
		{
			hozLoc = 512;
			vertLoc = 250;
		} else if (gameData().destination.name.equals("Fort Kearney") && gameData().distanceLeft > 0)
		{
			hozLoc = 512;
			vertLoc = 250;
		} else if (gameData().destination.name.equals("Fort Kearney") && gameData().distanceLeft <= 0)
		{
			hozLoc = 473;
			vertLoc = 231;
		} else if (gameData().destination.name.equals("Chimney Rock") && gameData().distanceLeft > 0)
		{
			hozLoc = 473;
			vertLoc = 231;
		} else if (gameData().destination.name.equals("Chimney Rock") && gameData().distanceLeft <= 0)
		{
			hozLoc = 383;
			vertLoc = 206;
		} else if (gameData().destination.name.equals("Fort Laramie") && gameData().distanceLeft > 0)
		{
			hozLoc = 383;
			vertLoc = 206;
		} else if (gameData().destination.name.equals("Fort Laramie") && gameData().distanceLeft <= 0)
		{
			hozLoc = 360;
			vertLoc = 197;
		} else if (gameData().destination.name.equals("Independence Rock") && gameData().distanceLeft > 0)
		{
			hozLoc = 360;
			vertLoc = 197;
		} else if (gameData().destination.name.equals("Independence Rock") && gameData().distanceLeft <= 0)
		{
			hozLoc = 315;
			vertLoc = 192;
		} else if (gameData().destination.name.equals("South Pass") && gameData().distanceLeft > 0)
		{
			hozLoc = 315;
			vertLoc = 192;
		} else if (gameData().destination.name.equals("South Pass") && gameData().distanceLeft <= 0)
		{
			hozLoc = 272;
			vertLoc = 206;
		} else if (gameData().destination.name.equals("Fort Bridger") && gameData().distanceLeft > 0)
		{
			hozLoc = 272;
			vertLoc = 206;
		} else if (gameData().destination.name.equals("Fort Bridger") && gameData().distanceLeft <= 0)
		{
			hozLoc = 259;
			vertLoc = 216;
		} else if (gameData().destination.name.equals("Green River") && gameData().distanceLeft > 0)
		{
			hozLoc = 272;
			vertLoc = 206;
		} else if (gameData().destination.name.equals("Green River") && gameData().distanceLeft <= 0)
		{
			hozLoc = 266;
			vertLoc = 182;
		} else if (gameData().destination.name.equals("Soda Springs") && gameData().distanceLeft > 0)
		{
			hozLoc = 266;
			vertLoc = 182;
		} else if (gameData().destination.name.equals("Soda Springs") && gameData().distanceLeft <= 0)
		{
			hozLoc = 242;
			vertLoc = 190;
		} else if (gameData().destination.name.equals("Fort Hall") && gameData().distanceLeft > 0)
		{
			hozLoc = 242;
			vertLoc = 190;
		} else if (gameData().destination.name.equals("Fort Hall") && gameData().distanceLeft <= 0)
		{
			hozLoc = 228;
			vertLoc = 176;
		} else if (gameData().destination.name.equals("Snake River") && gameData().distanceLeft > 0)
		{
			hozLoc = 228;
			vertLoc = 176;
		} else if (gameData().destination.name.equals("Snake River") && gameData().distanceLeft <= 0)
		{
			hozLoc = 191;
			vertLoc = 187;
		} else if (gameData().destination.name.equals("Fort Boise") && gameData().distanceLeft > 0)
		{
			hozLoc = 191;
			vertLoc = 187;
		} else if (gameData().destination.name.equals("Fort Boise") && gameData().distanceLeft <= 0)
		{
			hozLoc = 150;
			vertLoc = 149;
		} else if (gameData().destination.name.equals("Grande Ronde") && gameData().distanceLeft > 0)
		{
			hozLoc = 150;
			vertLoc = 149;
		} else if (gameData().destination.name.equals("Grande Ronde") && gameData().distanceLeft <= 0)
		{
			hozLoc = 135;
			vertLoc = 113;
		} else if (gameData().destination.name.equals("Fort Walla Walla") && gameData().distanceLeft > 0)
		{
			hozLoc = 135;
			vertLoc = 113;
		} else if (gameData().destination.name.equals("Fort Walla Walla") && gameData().distanceLeft <= 0)
		{
			hozLoc = 152;
			vertLoc = 92;
		} else if (gameData().destination.name.equals("The Dalles") && gameData().distanceLeft > 0)
		{
			hozLoc = 135;
			vertLoc = 113;
		} else if (gameData().destination.name.equals("The Dalles") && gameData().distanceLeft <= 0)
		{
			hozLoc = 103;
			vertLoc = 95;
		} else if (gameData().destination.name.equals("Willamette Valley") && gameData().distanceLeft > 0)
		{
			hozLoc = 103;
			vertLoc = 95;
		} else if (gameData().destination.name.equals("Willamette Valley") && gameData().distanceLeft <= 0)
		{
			hozLoc = 57;
			vertLoc = 90;
		}

		// draws background and wagon
		class Wagon extends JPanel
		{
			private static final long serialVersionUID = 1L;
			{
				
				int R = 8;
				int C = 6;

				setLayout(new GridLayout(R, C));

				for (int i = 0; i < R; i++)
					for (int j = 0; j < C; j++)
					{
						if (i == R - 1 && j == C - 1)
							break;
						add(new JPanel()
						{
							private static final long serialVersionUID = 1L;

							{
								setOpaque(false);
							}
						});
					}

				add(new JButton()
				{
					private static final long serialVersionUID = 1L;

					{
						setText("Close");
						addActionListener(new ActionListener()
						{
							public void actionPerformed(ActionEvent e)
							{
								dispose();
							}
						});
					}
				});
			}

			public void paintComponent(Graphics g)
			{
				super.paintComponent(g);
				g.drawImage(new ImageIcon("src/gtgold/img/OregonTrailMap.jpg")
						.getImage(), 0, 0, 640, 480, null);
				g.drawImage(
						new ImageIcon("src/gtgold/img/wagon.gif").getImage(),
						hozLoc - 16, vertLoc - 13, 32, 26, null);
			}
		}

		Wagon w = new Wagon();
		add(w);
		pack();
		setLocationRelativeTo(OregonTrail.frame);
		setVisible(true);
	}
	private GameData gameData()
	{
		return manager.data;
	}
}